Interactive Map

nyc_squirrels_clean_test <- nyc_squirrels_clean %>%
  mutate(label = primary_fur_color)%>%

  mutate(label = fct_recode(label,
  "https://inaturalist-open-data.s3.amazonaws.com/photos/176023507/original.jpeg" = "Gray",             "https://cms.prod.nypr.digital/images/329566/fill-1200x800%7Cformat-jpeg%7Cjpegquality-85" =   "Black",
  "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQub0O9b_HAjJjvFaz-w_d9sE6hsJLcRjadJfipfXv5udR5hPsKjsFcgXiKtxohSpQXB8I&usqp=CAU" = "Cinnamon"))



fur_color <- colorFactor(c("Black","Brown","Gray"),
                               domain = nyc_squirrels_clean$primary_fur_color)

 leaflet() %>% 
  addTiles() %>% 
  fitBounds(-73.9823592,40.7636484,-73.9492441, 40.8005539)%>%
  addTiles() %>% 
  addCircleMarkers(nyc_squirrels_clean$long, 
                   nyc_squirrels_clean$lat, 
                   color = fur_color(nyc_squirrels_clean$primary_fur_color), 
                   radius = 0.5, 
                   fill = T,
                   fillOpacity = 0.5,
                   opacity = 1,
                   popup = 
               paste('<img src="', nyc_squirrels_clean_test$label, '" alt="these be unis" width="200"><br>',
                     "<b>ID:</b>",nyc_squirrels_clean$unique_squirrel_id,"<br/>",
                     "<b>Color:</b>",nyc_squirrels_clean$primary_fur_color,"<br/>"))%>%
   addLegend("bottomright", pal = fur_color,
                         values = nyc_squirrels_clean$primary_fur_color,
                         title = "Primary fur color")

Interactive Graph

activity_percentages <- nyc_squirrels_clean %>% 
  select(running, chasing,climbing, eating, foraging, kuks, quaas, moans, 
         tail_flags, tail_twitches, indifferent, runs_from) %>% 
  rownames_to_column(var = "ID") %>% 
  as.data.frame() %>%
  as.data.frame() %>% 
  pivot_longer(cols = running:runs_from, names_to = "activity",
               values_to = "true_false") %>% 
  group_by(activity) %>% 
  nest() %>% 
  mutate(proportion = map(data, ~ .x %>% 
                            pull("true_false") %>% 
                            mean())) %>% 
  unnest(proportion) %>% 
  mutate(percentage = 100*proportion) %>% 
  select(activity, percentage) %>% 
  mutate(activity = gsub("_", " ", activity),
         activity =  str_to_title(activity),
         percentage = round(percentage, 2),
         tooltip_text = paste0(toupper(activity), "\n", 
                   percentage, "%"),
         tooltip_text = str_to_title(tooltip_text))

activity_graph <- activity_percentages %>% 
ggplot(aes(x = percentage, 
           y = reorder(activity, percentage), 
           fill = activity,
           tooltip = tooltip_text, data_id = activity
           )) +
  geom_col_interactive(color = "black", size = 0.3) +
  labs(x = "Percentage", y = "Activity", title = "Activity Percentages") +
  theme_few() +
  theme(legend.position = "none") +
  theme(plot.title=element_text(hjust=0.5))


girafe(ggobj = activity_graph, width_svg = 6, height_svg = 3.5)

Interactive Table

nyc_squirrels_filtered <- nyc_squirrels_clean %>% 
  select(primary_fur_color, age, date, unique_squirrel_id)

datatable(nyc_squirrels_filtered, colnames = c("Fur Color", "Age", "Date",
                                               "ID"), 
          extensions = "Scroller", style="bootstrap", class="compact", 
          width="100%", options=list(deferRender=TRUE, scrollY=300, 
                                     scroller=TRUE))